package demo.demo1;
import java.util.*;
import java.util.Objects;

public class Test {
    public static void main(String[] args) {
        int[] A={5,6,7,8,0,0,0,0};
        int[] B={1,2,3,4};
        int m=4;
        int n=B.length;
        soution(A,m,B,n);
    }
    public static void soution(int[] A,int m,int[] B,int n)
    {
        int i=m-1;
        int j=n-1;
        int t=m+n-1;
        while(i>=0&&j>=0)
        {
            if(A[i]>B[j])
            {
                A[t]=A[i];
                t--;
                i--;
            }
            else
            {
                A[t]=B[j];
                t--;
                j--;
            }

        }
        while(j>=0)
        {
        A[t]=B[j];
        t--;
        j--;
        }
        //Arrays.sort(A);
        System.out.println(Arrays.toString(A));
    }
}
